package game.Engine.Client;

import org.feiteira.network.copy.SeriDataPackage;
import org.feiteira.network.copy.SeriEventHandler;

import game.MainController;

import java.io.IOException;
import java.io.Serializable;
import java.util.Vector;

public class ClientEventHandler implements SeriEventHandler {

	@Override
	public void messageArrived(SeriDataPackage pack) {
		Serializable fromServer = pack.getObject();
		if(fromServer instanceof Vector<?>){
			MainController.gameEngine.replaceEntities((Vector)fromServer);
		}else if(fromServer instanceof String){
			String s = (String)fromServer;
			if(s.equalsIgnoreCase("Bye")){
				try {
					pack.getSocket().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}else if(s.startsWith("ID")){
				String stringID = s.substring(2, s.length());
				MainController.setID(Integer.parseInt(stringID));
			}
		}
	}

	@Override
	public void shutdownCompleted() {
		
	}
}